Skip to content

feat(predict): remove CLOB v1 support and migrate to pUSD cp-7.76.0#29451

Merged
matallui merged 9 commits into
mainfrom
predict/clob-v2-cleanup-core
May 6, 2026
Merged

feat(predict): remove CLOB v1 support and migrate to pUSD cp-7.76.0#29451
matallui merged 9 commits into
mainfrom
predict/clob-v2-cleanup-core

Conversation

@matallui
Copy link
Copy Markdown
Contributor

@matallui matallui commented Apr 28, 2026

Description

This PR removes legacy Predict Polymarket CLOB v1 support and completes the pUSD migration in Predict-owned code.

It includes:

  • CLOB v2 as the unconditional Polymarket protocol path.
  • Removal of CLOB v1 protocol selection, order codec branches, and v1 Safe helper wrappers.
  • pUSD as the canonical Predict trading, fee, deposit, withdraw, reward-fee, and claim gas top-up token.
  • Legacy Safe USDC.e retained only as temporary hidden sweep state.
  • Legacy USDC.e → pUSD sweep preflight for deposit, withdraw, trade, and claim operations.
  • Displayed Predict balance as total recoverable Predict funds (pUSD + legacy USDC.e).
  • In-memory cache to stop refetching legacy USDC.e balance for a Safe after a zero balance is observed.

Stack note: this PR is stacked on the confirmations-only pUSD PR so the diff stays limited to Predict-owned files.

Changelog

CHANGELOG entry: Updated Predict to use pUSD and the Polymarket CLOB v2 protocol.

Related issues

Fixes: PRED-851 , PRED-852

Manual testing steps

Feature: Predict pUSD migration

  Scenario: user with pUSD places a Predict trade
    Given the user has a funded Predict Safe with pUSD
    When the user places a Predict trade
    Then the order is submitted through the CLOB v2 path
    And pUSD is used for trading and fee authorization

  Scenario: legacy user performs their first Predict operation
    Given the user has legacy USDC.e in their Predict Safe
    When the user deposits, withdraws, trades, or claims
    Then the Safe preflight wraps legacy USDC.e into pUSD before the main operation

Screenshots/Recordings

Before

N/A — code-only protocol migration PR; no screenshots captured.

After

N/A — code-only protocol migration PR; no screenshots captured.

Testing

  • yarn lint:tsc
  • yarn jest app/components/UI/Predict/providers/polymarket/protocol/definitions.test.ts app/components/UI/Predict/providers/polymarket/protocol/orderCodec.test.ts app/components/UI/Predict/providers/polymarket/protocol/transport.test.ts app/components/UI/Predict/providers/polymarket/preflight/v2AllowanceRequirements.test.ts app/components/UI/Predict/providers/polymarket/preflight/withdraw.test.ts app/components/UI/Predict/providers/polymarket/preflight/workflows.test.ts app/components/UI/Predict/providers/polymarket/PolymarketProvider.test.ts app/components/UI/Predict/controllers/PredictController.test.ts app/components/UI/Predict/hooks/usePredictBalanceTokenFilter.test.ts app/components/UI/Predict/hooks/usePredictRewards.test.ts app/components/UI/Predict/views/PredictBuyWithAnyToken/components/PredictPayWithRow/PredictPayWithRow.test.tsx --runInBand --forceExit

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Medium Risk
Updates on-chain token identifiers/addresses used for Predict gas fee and rewards calculations, which could impact transactions if misconfigured. Changes are localized to Predict hooks/controller and accompanying tests.

Overview
Predict now consistently references the pUSD / CLOB v2 collateral across Predict-owned code: PredictController uses MATIC_CONTRACTS_V2.collateral as the gasFeeToken for claim/withdraw addTransactionBatch, usePredictBalanceTokenFilter displays the Predict balance row using the POLYGON_PUSD token (icon + symbol), and usePredictRewards estimates points using POLYGON_PUSD_CAIP_ASSET_ID.

Cleans up account-state handling by removing hasAllowances expectations/tests and updating usePredictAccountState docs to reflect the slimmer AccountState shape.

Reviewed by Cursor Bugbot for commit 7dfda61. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions
Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbotv2 metamaskbotv2 Bot added the team-predict Predict team label Apr 28, 2026
@matallui matallui marked this pull request as ready for review April 29, 2026 18:34
@matallui matallui requested a review from a team as a code owner April 29, 2026 18:34
Base automatically changed from predict/pusd-confirmations to main April 29, 2026 19:20
@matallui matallui requested a review from a team as a code owner April 29, 2026 19:20
@matallui matallui force-pushed the predict/clob-v2-cleanup-core branch from 4e3b5ca to ac40f1d Compare April 29, 2026 19:39
@matallui matallui force-pushed the predict/clob-v2-cleanup-core branch from a8fc740 to 80436b3 Compare April 29, 2026 20:05
@matallui matallui removed the request for review from a team April 29, 2026 20:06
@matallui matallui requested a review from a team as a code owner April 29, 2026 21:41
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 29, 2026

Codecov Report

❌ Patch coverage is 86.02151% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.42%. Comparing base (8437791) to head (f27f7d3).
⚠️ Report is 127 commits behind head on main.

Files with missing lines Patch % Lines
...Predict/providers/polymarket/PolymarketProvider.ts 85.71% 3 Missing and 1 partial ⚠️
...omponents/UI/Predict/providers/polymarket/utils.ts 81.25% 2 Missing and 1 partial ⚠️
...redict/providers/polymarket/protocol/orderCodec.ts 50.00% 1 Missing and 1 partial ⚠️
.../UI/Predict/providers/polymarket/preflight/core.ts 83.33% 0 Missing and 1 partial ⚠️
.../Predict/providers/polymarket/preflight/deposit.ts 75.00% 1 Missing ⚠️
...UI/Predict/providers/polymarket/preflight/trade.ts 66.66% 0 Missing and 1 partial ⚠️
...ents/UI/Predict/providers/polymarket/safe/utils.ts 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #29451      +/-   ##
==========================================
- Coverage   81.86%   81.42%   -0.44%     
==========================================
  Files        5255     5301      +46     
  Lines      138980   140423    +1443     
  Branches    31518    31956     +438     
==========================================
+ Hits       113774   114345     +571     
- Misses      17465    18257     +792     
- Partials     7741     7821      +80     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

caieu
caieu previously approved these changes Apr 30, 2026
caieu
caieu previously approved these changes Apr 30, 2026
@matallui matallui changed the title feat(predict): remove CLOB v1 support and migrate to pUSD feat(predict): remove CLOB v1 support and migrate to pUSD cp-7.76.0 Apr 30, 2026
@matallui matallui force-pushed the predict/clob-v2-cleanup-core branch from 6ff7cb7 to 80436b3 Compare May 5, 2026 16:36
# By metamaskbot (20) and others
# Via GitHub (10) and others
* main: (144 commits)
  fix: transaction page display and alerts for money account transactions (#29725)
  feat: replace assets state references in Engine (#29727)
  fix: display non ETH native transactions in the native token detail page (#28977)
  chore(card): migrate Card BigInt usage to new library (#29679)
  fix(perps): suppress transient HL SDK errors from Sentry (#29642)
  feat: bump Accounts dependencies (#29621)
  feat(ramp): bypass order-processing redirect in headless flows (Phase 6) (#29340)
  feat: tempo disable tx management for testnet moderato (#29425)
  feat: support max money account deposit for ERC-20 tokens (#29605)
  fix(BETR-413): pass originalTransactionId for intent bridge history cp-7.76.0 (#29670)
  feat: add hook for updating MM pay transaction amount update for money account deposits (#29561)
  chore: explore v2 nit fixes (#29720)
  test: MMQA -1712-[Mobile] Update the mobile e2e tests to account for home page redesign enabled (#29100)
  feat: display 5 year projected balance on money account deposit page (#29607)
  feat(rewards): add Perps Trading Campaign (#29323)
  ci: extract mobile CI status gate (#29619)
  fix(ci): improve CocoaPods install resilience against CDN rate limiting (#29334)
  fix(ci): add restore-keys and continue-on-error to yarn cache (#29277)
  chore: TSA-488-1 bump ai-controller (#29678)
  fix: top traders section disappears on fetch error (#29501)
  ...

# Conflicts:
#	app/components/UI/Predict/hooks/usePredictBalanceTokenFilter.test.ts
#	app/components/UI/Predict/hooks/usePredictBalanceTokenFilter.ts
#	app/components/UI/Predict/providers/polymarket/utils.test.ts
@matallui matallui requested a review from a team as a code owner May 5, 2026 17:01
@matallui matallui removed the request for review from a team May 5, 2026 17:08
@matallui matallui removed the request for review from a team May 5, 2026 17:10
@matallui matallui force-pushed the predict/clob-v2-cleanup-core branch from 80f5c73 to d9f1abb Compare May 5, 2026 20:32
matallui and others added 4 commits May 5, 2026 15:08
* main:
  chore: set user timezone in chart (#29654)
  fix: MUSD-771 updated selectAccountTokensAcrossChainsUnified to select tokens across chains for evm-scope specifically cp-7.76.0 (#29675)
  fix: resolve `ORDER_PRICE_REQUIRED` error on perps position flip (#29691)
  fix(activity): restore Perps after popular networks without forcing Ethereum (#29676)
  fix: resolve token block explorer from network configurations (#29686)
  chore: New Crowdin Translations by GitHub Action cp-7.76.0 (#29535)
  feat: TSA 488-2 Whats Happening expanded view + Explore page (#29681)
  test(e2e): mock popular network RPCs to remove from allowlist (MMQA-1785) (#29682)
  feat(analytics): emit dapp_name + dapp_url on Remote Connection Request Received/Failed (#29746)
  fix: make in-app webview back button tappable on iOS (#29693)
@matallui matallui enabled auto-merge May 6, 2026 16:47
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePredictions, SmokeConfirmations, SmokeWalletPlatform
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: high
  • AI Confidence: 90%
click to see 🤖 AI reasoning details

E2E Test Selection:
This PR implements a significant migration of the Polymarket Predictions feature from CLOB v1 to v2 exclusively, with pUSD replacing USDC.e as the collateral token.

SmokePredictions (primary): All Predictions E2E tests must run because:

  • The entire Polymarket protocol has been migrated from v1 to v2 exclusively (POLYMARKET_V1_PROTOCOL removed)
  • The collateral token changed from USDC.e to pUSD (POLYGON_PUSD_TOKEN_ADDRESS)
  • Deposit, withdraw, claim, and trade flows all have updated transaction building logic
  • Mock responses in polymarket-mocks.ts have been substantially updated to reflect pUSD balance checks
  • The predict-open-position, predict-cash-out, predict-claim-positions, predict-withdraw, predict-existing-polymarket-balance, and predict-api-down tests all use these mocks
  • The POLYMARKET_POST_CASH_OUT_MOCKS matcher was updated to match CLOB v2 order shape (removed v1-only fields: taker, nonce, feeRateBps; added v2 fields: timestamp, metadata, builder)

SmokeConfirmations (required per tag description): The transaction-pay.spec.ts test (SmokeConfirmations tag) was modified to skip the 'deposits to predict balance' test. This test file is directly changed and needs to be validated. Additionally, SmokePredictions tag description explicitly states 'also select SmokeConfirmations (opening/closing positions are on-chain transactions)'.

SmokeWalletPlatform (required per tag description): SmokePredictions description states 'also select SmokeWalletPlatform (Trending section)' since Perps/Predictions are sections inside the Trending tab.

Not selected: SmokeAccounts, SmokeIdentity, SmokeNetworkAbstractions, SmokeNetworkExpansion, SmokeSwap, SmokeStake, SmokeMoney, SmokePerps, SmokeMultiChainAPI, SmokeBrowser, SmokeSnaps, SmokeSeedlessOnboarding - none of these are affected by Polymarket CLOB v2 migration changes.

Performance Test Selection:
The changes are focused on Polymarket Predictions business logic (CLOB v2 migration, pUSD token migration, protocol definitions, preflight workflows). These are not UI rendering changes, not list/component rendering changes, and do not affect app startup, login, or core navigation. The changes are primarily to transaction building logic, API key management, and mock responses. No performance-sensitive code paths (account list rendering, onboarding screens, swap quote fetching, app launch) are affected.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 6, 2026

@matallui
Copy link
Copy Markdown
Contributor Author

matallui commented May 6, 2026

Adding @cryptotavares to the Predict team temporarily so he can approve the PR, since all available team members have touched the PR and cannot approve it anymore.

@matallui matallui requested a review from a team May 6, 2026 17:50
@matallui matallui added this pull request to the merge queue May 6, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 6, 2026
@matallui matallui added this pull request to the merge queue May 6, 2026
Merged via the queue into main with commit bf54b9b May 6, 2026
116 of 137 checks passed
@matallui matallui deleted the predict/clob-v2-cleanup-core branch May 6, 2026 18:25
@github-actions github-actions Bot locked and limited conversation to collaborators May 6, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.77.0 Issue or pull request that will be included in release 7.77.0 label May 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.77.0 Issue or pull request that will be included in release 7.77.0 size-XL team-predict Predict team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants